package com.api.workflow.util;

import cn.hutool.http.HttpRequest;
import org.json.JSONException;
import org.json.JSONObject;
import weaver.general.BaseBean;


/**
 * 该方法只处理http请求发送，接收响应，不对传递的数据or接收的数据进行解析操作
 * 解析处理需要自行定义在对应的方法里
 * 调用方式
 * 1/获取token
 * 2/调用接口
 * 在各自的方法里取处理数据，不要在这个工具方法里去处理数据
 */
public class YNHttpUtils {
    /**
     * 获取token
     */
    public static String token() throws JSONException {
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog("=========token");
        String token = null;
        String tokenzsysid = baseBean.getPropValue("YNSap", "tokenzsysid");
        String tokenusername = baseBean.getPropValue("YNSap", "tokenusername");
        String tokenpassword = baseBean.getPropValue("YNSap", "tokenpassword");
        String tokenUrl = baseBean.getPropValue("YNSap", "tokenUrl");
        JSONObject requestBody = new JSONObject();
        requestBody.put("zsysid", tokenzsysid);
        requestBody.put("username", tokenusername);
        requestBody.put("password", tokenpassword);
        String post = HttpRequest.post(tokenUrl)
                .header("Content-Type", "application/json")
                .body(requestBody.toString())
                .execute()
                .body();
        JSONObject jsonObject = new JSONObject(post);
        String STATUS = jsonObject.getString("STATUS");
        if (STATUS.equals("S")) {
            token = jsonObject.getString("TOKEN");
        }

        return token;
    }

    /**
     * PMI001 设备台账查询接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String PMI001(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "PMI001Url");
        String sysid = baseBean.getPropValue("YNSap", "PMI001sysid");
        String ifid = baseBean.getPropValue("YNSap", "PMI001ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();

    }

    /**
     * PMI002 设备变更接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String PMI002(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "PMI002Url");
        String sysid = baseBean.getPropValue("YNSap", "PMI002sysid");
        String ifid = baseBean.getPropValue("YNSap", "PMI002ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();

    }

    /**
     * PMI003 功能位置查询接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String PMI003(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "PMI003Url");
        String sysid = baseBean.getPropValue("YNSap", "PMI003sysid");
        String ifid = baseBean.getPropValue("YNSap", "PMI003ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();

    }


    /**
     * FII002 OA与SAP付款申请接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII002(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII002Url");
        String sysid = baseBean.getPropValue("YNSap", "FII002sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII002ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * FII003 内部订单主数据创建接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII003(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII003Url");
        String sysid = baseBean.getPropValue("YNSap", "FII003sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII003ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * FII004 采购订单付款信息获取接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII004(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII004Url");
        String sysid = baseBean.getPropValue("YNSap", "FII004sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII004ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * MMI001 处理_需求计划创建/变更接口(外围系统->SAP)
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI001(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI001Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI001sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI001ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * MMI003 采购申请退回(外围系统->SAP)
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI003(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI003Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI003sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI003ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * MMI005 采购订单创建及变更接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI005(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI005Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI005sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI005ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * MMI004 供应商主数据创建/修改接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI004(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI004Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI004sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI004ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * MMI023 非生产物资验收
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI023(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI023Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI023sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI023ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * MMI027库存查询接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI027(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI027Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI027sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI027ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * MMI030物料主数据创建接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI030(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI030Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI030sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI030ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * MMI032  质量信息接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String MMI032(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "MMI032Url");
        String sysid = baseBean.getPropValue("YNSap", "MMI032sysid");
        String ifid = baseBean.getPropValue("YNSap", "MMI032ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII009 OA获取SAP内部订单
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII009(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII009Url");
        String sysid = baseBean.getPropValue("YNSap", "FII009sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII009ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII010 OA获取SAP供应商应付账款
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII010(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII010Url");
        String sysid = baseBean.getPropValue("YNSap", "FII010sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII010ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII010 OA获取SAP供应商应付账款
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII010A(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII010AUrl");
        String sysid = baseBean.getPropValue("YNSap", "FII010Asysid");
        String ifid = baseBean.getPropValue("YNSap", "FII010Aifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII014 OA获取SAP资产价值
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII014(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII014Url");
        String sysid = baseBean.getPropValue("YNSap", "FII014sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII014ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII011 资产主数据创建接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII011(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII011Url");
        String sysid = baseBean.getPropValue("YNSap", "FII011sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII011ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII012 资产报废接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII012(String jsonBody, String token) {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII012Url");
        String sysid = baseBean.getPropValue("YNSap", "FII012sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII012ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * FII013 资产调拨接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String FII013(String jsonBody, String token) throws JSONException {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "FII013Url");
        String sysid = baseBean.getPropValue("YNSap", "FII013sysid");
        String ifid = baseBean.getPropValue("YNSap", "FII013ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }


    /**
     * SDI003 客户授信接口
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String SDI003(String jsonBody, String token) throws JSONException {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "SDI003Url");
        String sysid = baseBean.getPropValue("YNSap", "SDI003sysid");
        String ifid = baseBean.getPropValue("YNSap", "SDI003ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

    /**
     * SDI011 查询_客户销售数据同步(外围系统->SAP)
     *
     * @param jsonBody
     * @param token
     * @return
     */
    public static String SDI011(String jsonBody, String token) throws JSONException {
        BaseBean baseBean = new BaseBean();
        String url = baseBean.getPropValue("YNSap", "SDI011Url");
        String sysid = baseBean.getPropValue("YNSap", "SDI011sysid");
        String ifid = baseBean.getPropValue("YNSap", "SDI011ifid");
        return HttpRequest.post(url)
                .header("Content-Type", "application/json")
                .header("sysid", sysid)
                .header("ifid", ifid)
                .header("token", token)
                .body(jsonBody)
                .execute()
                .body();
    }

}
